#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>

void* Memcpy(void* dst, const void* src, size_t n)
{
	assert(dst && src);

	for (size_t i = 0; i < n; ++i)
	{
		((char*)dst)[i] = ((char*)src)[i];
	}

	return dst;
}

void Test1()
{
	char* pc = "string test!";
	int dst[100];
	int src[] = {1, 2, 3, 4, 5};

	//memcpy(dst, src, sizeof(src));
	Memcpy(dst, src, sizeof(src));
	for (int i = 0; i < sizeof(src) / sizeof(src[0]); ++i)
	{
		printf("%d ", dst[i]);
	}
	putchar('\n');

	//memcpy(dst, pc, strlen(pc)+1);
	//Memcpy(dst, pc, strlen(pc)+1);
}

void Test2()
{
	char p[100] = "hello world";
	char ps[3] = {'a', 'b', 'c'};

	//strncat(p, p, strlen(p) + 1);
	//strcat(p, ps);
}

void* Memmove(void* dst, const void* src, size_t n)
{
	assert(dst && src);

	char* tmp = (char*)malloc(sizeof(char) * n);
	assert(tmp);

	for (size_t i = 0; i < n; ++i)
	{
		tmp[i] = ((char*)src)[i];
	}

	for (size_t i = 0; i < n; ++i)
	{
		((char*)dst)[i] = tmp[i];
	}

	free(tmp);
	tmp = NULL;

	return dst;
}

void Test3()
{
	char p[100] = "memmove is very useful......";

	printf("%s\n", p);
	Memmove(p+16, p + 11, 11);
	printf("%s\n", p);
}

int main()
{
	//Test1();
	//Test2();
	Test3();

	return 0;
}